﻿using System;
using System.Collections.Generic;
using System.Text;
using MOD;
using System.Data.OleDb;

namespace DOM
{
    /// <summary>
    /// Users 的摘要说明。
    /// </summary>
    public class Users
    {
        public Users()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        public int CheckPasswd(string userName, string passwd)
        {
            UserInfo userInfo = new UserInfo();
            OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data\selectCourse.mdb");
            con.Open();
            OleDbCommand cmd = con.CreateCommand();
            cmd.CommandText = "SELECT purview FROM users WHERE userName='" + userName + "'" + " AND passwd=" + "'" + passwd + "'";
            OleDbDataReader reader = cmd.ExecuteReader();
            int i;
            if (reader.Read())
            {
                userInfo.Purview = (int)reader["purview"];
                i = userInfo.Purview;
                con.Close();
                return i;
            }
            else
            {
                return -1;
            }


        }
        public bool UpdatePasswd(string userName, string passwd)
        {
            OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data\selectCourse.mdb");
            try
            {
                con.Open();
                //string queryStr = " UPDATE users SET passwd=@passwd WHERE userName=@userName";
                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = con;
                cmd.CommandText =@" UPDATE users SET passwd='321' WHERE userName='admin' ";
                cmd.Parameters.AddWithValue("@userName", userName);
                cmd.Parameters.AddWithValue("@passwd", passwd);
                cmd.ExecuteNonQuery();
                con.Close();
                return true;
            }
            catch (Exception )
            {
                return false;
            }
        }


    }
}
